%%
% 
%  This script plot the result of the simulation in meshes for velocity and
%  preassure over the time.
% 


%%  Load dependencies
%addpathsCFD;

%% Plot Structures

[Xp1, Xp2, PT1, PT2] = PspatialMapPerBlock( h , NIt , NJt , NJe , NIe , PT);
[Xu1, Xu2, UT1, UT2] = UspatialMapPerBlock( h , NIut , NJut , NJue , NIue , UT);
[Xv1, Xv2, VT1, VT2] = VspatialMapPerBlock( h , NIvt , NJvt , NJve , NIve , VT); 



%% Plot pressure 

% figure(1) 
%  
% tri1 = delaunay(Xp1(:,1),Xp1(:,2));
% tri2 = delaunay(Xp2(:,1),Xp2(:,2));
% 
% az = 0;
% el = 90;
% 
% for i=1:floor((T1-T0)/(dt*nSkip))
%     trisurf(tri1, Xp1(:,1), Xp1(:,2), PT1(:,i));hold on;
%     pbaspect ([12 2 1])
%     trisurf(tri2, Xp2(:,1), Xp2(:,2), PT2(:,i));hold off;
%     view(az, el);
% 
%     title(strcat('pressure at time =',num2str(T0+i*dt*nSkip),'seg.'));
%     maxPT = max(max(PT));
%     minPT = min(min(PT));
%     zlim([minPT maxPT]);
%     pause(0.01);
% end
% 
% %% Plot velocity x
% 
% figure(2) 
% 
% tri1 = delaunay(Xu1(:,1),Xu1(:,2));
% tri2 = delaunay(Xu2(:,1),Xu2(:,2));
% 
% az = 0;
% el = 90;
% 
% for i=1:floor((T1-T0)/(dt*nSkip))
%     trisurf(tri1, Xu1(:,1), Xu1(:,2), UT1(:,i));hold on;
%     pbaspect ([12 2 1])
%     trisurf(tri2, Xu2(:,1), Xu2(:,2), UT2(:,i));hold off;
%     view(az, el);
% 
%     title(strcat('velocity u at time =',num2str(T0+i*dt*nSkip),'seg.'));
%     maxUT = max(max(UT));
%     minUT = min(min(UT));
%     zlim([minUT maxUT]);
%     pause(0.01);
% end
% 
% 
% %% Plot velocity y
% 
% figure(3) 
% 
% tri1 = delaunay(Xv1(:,1),Xv1(:,2));
% tri2 = delaunay(Xv2(:,1),Xv2(:,2));
% 
% az = 0;
% el = 90;
% 
% for i=1:floor((T1-T0)/(dt*nSkip))
%     trisurf(tri1, Xv1(:,1), Xv1(:,2), VT1(:,i));hold on;
%     pbaspect ([12 2 1])
%     trisurf(tri2, Xv2(:,1), Xv2(:,2), VT2(:,i));hold off;
%     view(az, el);
% 
%     title(strcat('velocity v at time =',num2str(T0+i*dt*nSkip),'seg.'));
%     maxVT = max(max(VT));
%     minVT = min(min(VT));
%     zlim([minVT maxVT]);
%     pause(0.01);
% end

%%  Plot all

figure(4) 

trip1 = delaunay(Xp1(:,1),Xp1(:,2));
trip2 = delaunay(Xp2(:,1),Xp2(:,2));
triu1 = delaunay(Xu1(:,1),Xu1(:,2));
triu2 = delaunay(Xu2(:,1),Xu2(:,2));
triv1 = delaunay(Xv1(:,1),Xv1(:,2));
triv2 = delaunay(Xv2(:,1),Xv2(:,2));

az = 0;
el = 90;



for i=1:floor((T1-T0)/(dt*nSkip))
    subplot(3,1,1), trisurf(trip1, Xp1(:,1), Xp1(:,2), PT1(:,i));hold on;
    pbaspect ([12 2 1])
    subplot(3,1,1), trisurf(trip2, Xp2(:,1), Xp2(:,2), PT2(:,i));hold off;
    view(az, el);
    
    title(strcat('pressure at time =',num2str(T0+i*dt*nSkip),'seg.'));
    maxPT = max(max(PT));
    minPT = min(min(PT));
    zlim([minPT maxPT]);
    colorbar
    
    
    subplot(3,1,2), trisurf(triu1, Xu1(:,1), Xu1(:,2), UT1(:,i));hold on;
    pbaspect ([12 2 1])
    subplot(3,1,2), trisurf(triu2, Xu2(:,1), Xu2(:,2), UT2(:,i));hold off;
    view(az, el);
    
    title(strcat('velocity u at time =',num2str(T0+i*dt*nSkip),'seg.'));
    maxUT = max(max(UT));
    minUT = min(min(UT));
    zlim([minUT maxUT]);
    shading interp;
    colorbar
    
    subplot(3,1,3), trisurf(triv1, Xv1(:,1), Xv1(:,2), VT1(:,i));hold on;
    pbaspect ([12 2 1])
    subplot(3,1,3), trisurf(triv2, Xv2(:,1), Xv2(:,2), VT2(:,i));hold off;
    view(az, el);
    
    title(strcat('velocity v at time =',num2str(T0+i*dt*nSkip),'seg.'));
    maxVT = max(max(VT));
    minVT = min(min(VT));
    zlim([minVT maxVT]);
    shading interp;
    colorbar
    pause(0.01);
end
